$(function () {
    let form = layui.form
    form.verify({
        nickname: [
            /^[\S]{1,10}$/,
            '昵称的长度为1-10个字符！'
        ]


    })
    let layer = layui.layer
    initUserInfo()
   
    function initUserInfo() {
        axios({
            method: 'get',
            url: '/my/userinfo'
        }).then(res => {
            //console.log(res);
            if (res.data.status !== 0) {
                return layer.msg(res.data.message)
            }
            console.log(res.data.data);
            form.val("formUserInfo", res.data.data)
        })

    }
     //重置信息
    $("#btnReset").on('click', function (e) {
        e.preventDefault()
        initUserInfo()
    })
    //修改信息
    $('form').on('submit', function (e) {
        e.preventDefault()
        axios({
            method: 'POST',
            url: '/my/userinfo',
            data: $(this).serialize()
        }).then(res => {
            if (res.data.status !== 0) {
                return layer.msg(res.data.message)
            }
            layer.msg('修改成功')
            window.parent.getuserinfo()
        })
    })

})
